package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.JjGpc;
import com.stylefeng.guns.modular.system.service.IJjGpcService;
import com.stylefeng.guns.modular.system.warpper.JjGpcWarpper;

/**
 * 竞价捉妖控制器
 *
 * @author fengshuonan
 * @Date 2018-08-08 13:43:47
 */
@Controller
@RequestMapping("/jjGpc")
public class JjGpcController extends BaseController {

    private String PREFIX = "/system/jjGpc/";

    @Autowired
    private IJjGpcService jjGpcService;

    /**
     * 跳转到竞价捉妖首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "jjGpc.html";
    }

    /**
     * 跳转到添加竞价捉妖
     */
    @RequestMapping("/jjGpc_add")
    public String jjGpcAdd() {
        return PREFIX + "jjGpc_add.html";
    }

    /**
     * 跳转到修改竞价捉妖
     */
    @RequestMapping("/jjGpc_update/{jjGpcId}")
    public String jjGpcUpdate(@PathVariable Integer jjGpcId, Model model) {
        JjGpc jjGpc = jjGpcService.selectById(jjGpcId);
        model.addAttribute("item",jjGpc);
        LogObjectHolder.me().set(jjGpc);
        return PREFIX + "jjGpc_edit.html";
    }

    /**
     * 获取竞价捉妖列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date) {
    	Page<JjGpc> page = new PageFactory<JjGpc>().defaultPage();
    	List<Map<String, Object>> gdhs = jjGpcService.selectMapsByDate(page,date);
    	page.setRecords((List<JjGpc>) new JjGpcWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增竞价捉妖
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(JjGpc jjGpc) {
        jjGpcService.insert(jjGpc);
        return SUCCESS_TIP;
    }

    /**
     * 删除竞价捉妖
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer jjGpcId) {
        jjGpcService.deleteById(jjGpcId);
        return SUCCESS_TIP;
    }

    /**
     * 修改竞价捉妖
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(JjGpc jjGpc) {
        jjGpcService.updateById(jjGpc);
        return SUCCESS_TIP;
    }

    /**
     * 竞价捉妖详情
     */
    @RequestMapping(value = "/detail/{jjGpcId}")
    @ResponseBody
    public Object detail(@PathVariable("jjGpcId") Integer jjGpcId) {
        return jjGpcService.selectById(jjGpcId);
    }
}
